﻿@using FTBS.Models.Entities;
@model List<FTBS.Models.Entities.Promotion>
@{    
    ViewBag.Title = "Phim đang khuyến mãi"; 
    Layout = "~/Views/Shared/_Layout.cshtml";
   var listSchedules = (List<Schedule>)ViewBag.ListSchedule;
   string minutes = "";
   string hours = "";
   var currentHour = DateTime.Now.Hour;
   var currentDay = DateTime.Now;
}
<style>
        .description {
        display: -webkit-box;
        max-width: 100%;
        margin: 0 auto;
        font-size: 12px;
        line-height: 1px;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .filmkind {
        padding: 5px; 
        font-size: 27px; 
        background-color: rgb(83, 141, 160); 
        color: white;
    }
    .filminfo {
    width: 100%; 
    padding-left: 20px;
    border-bottom: #ddd 1px solid;
    padding-bottom: 5px;
    border-top: solid 1px #fff;
    }
    .filmpart {
    display: inline-block; 
    vertical-align: top;
    }
    .filmtitle {
    font-size: 21px; 
    color: red;
    }
    .showtime {
        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#E46B54), to(#251613));
        width: 49px;
        text-align: center;
        border-radius: 3px;
       margin: 2px 2px 2px 25px;
        display: inline-block;
    }

</style>
@if (Model.Count > 0 && Model[0]!= null)
{ 
    <div class="panel" style="background-color: white; margin-top: 20px; margin-left: 15px; width: 97.5%">
        @for (int j = 0; j < Model.Count ; j++)
        {
            <div class="filmkind">
                @Html.DisplayFor(Pro => Model[j].PromotionName)
            </div>  
            if (Model[j] != null)
            {
                var listFilmPro = listSchedules.Where(s => s.PromotionId == Model[j].PromotionId).Select(s => s.Film).Distinct().ToList();
                
                for (int i = 0; i < listFilmPro.Count() ; i++)
                { 
            <div class="filminfo">
                <div class="filmpart" style="width: 20%">
                    <div class="filmtitle">@listFilmPro[i].Name
                        <div style="border: 1px solid black">
                            <a href="/Home/Detail/@listFilmPro[i].FilmId">
                                <img src="~/Image/FilmImage/@listFilmPro[i].ImageURL" style="height: 230px; width: 100%"/>
                            </a>
                        </div>
                    </div>
                </div>
                <div class="filmpart" style="width: 40%; margin: 0px 30px 0px 10px;">
                    <div style="margin-top: 27px; height: 20%;">
                        <p class="description" style="line-height: 13pt">@listFilmPro[i].Description</p>
                    </div>
                    <div style="margin-top: 10px; border-radius: 5px;">
                        <table class="table striped bordered hovered">
                            <tr>
                                <td style="width: 100px; font-weight: bold">Thể Loại:</td>
                                <td>@listFilmPro[i].Category.CategoryName</td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold">Diễn viên:</td>
                                <td>@listFilmPro[i].Actor</td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold">Đạo diễn:</td>
                                <td>@listFilmPro[i].Director</td>
                            </tr>
                            <tr>
                                <td style="font-weight: bold">Định dạng: </td>
                                <td>@listFilmPro[i].Format.FormatName</td>
                            </tr>

                        </table>
                    </div>
                </div>
                <div class="filmpart" style ="width: 30%;overflow-y: auto; height: 280px;padding:0px 0px 0px 20px; margin:10px 0px 10px 0px; border:solid 1px #ddd;background-color:rgba(223, 215, 37, 0.36)"   >
                    @{ 
                    var listOnTheater = listSchedules.Where(s => s.FilmId == listFilmPro[i].FilmId).Select(s => s.Theater.TheaterName).Distinct();

                    foreach (var theater in listOnTheater)
                    {
                        var listOnDate = listSchedules.Where(s => s.FilmId == listFilmPro[i].FilmId && s.Theater.TheaterName == @theater).Select(s => s.Date).Distinct();      
                    
              
                         <strong style="margin-top:5px">@theater</strong>
                        foreach (var date in listOnDate)
                        {
                        <div style="font-size: 15px;padding:5px 0px 5px 15px">@date.ToString("dd/MM/yyyy")</div>  
                            var listOnTime = listSchedules.Where(s => s.FilmId == listFilmPro[i].FilmId && s.Theater.TheaterName == @theater && s.Date == @date);
                            foreach (var item in listOnTime)
                            {
                               
                                var showtimeHour = item.ShowTime.Time.Hours;
                                var showtimeDay = item.Date;
                                if (item.ShowTime.Time.Minutes < 10)
                                {
                                    minutes = "0" + item.ShowTime.Time.Minutes.ToString();
                                }
                                else if (item.ShowTime.Time.Minutes >= 10)
                                {
                                    minutes = item.ShowTime.Time.Minutes.ToString();
                                }

                                if (item.ShowTime.Time.Hours < 10)
                                {
                                    hours = "0" + item.ShowTime.Time.Hours.ToString();
                                }
                                else if (item.ShowTime.Time.Hours >= 10)
                                {
                                    hours = item.ShowTime.Time.Hours.ToString();
                                }
                                if (showtimeDay == currentDay)
                                {
                              if (showtimeHour >= currentHour + (item.Theater.DeadlineForBooking / 60))
                                {
                                         <div class="showtime">@Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", "Schedule", new {@showtimeId = item.ShowTime.ShowTimeId, @filmId = item.FilmId, @theaterId = item.TheaterId, @roomId = item.RoomId, @scheduleId = item.ScheduleId}, new { style="color:white"}) </div>
                                }
                                if (showtimeHour < currentHour + (item.Theater.DeadlineForBooking / 60))
                                {
                                <button class="button small" style="color: black; margin-left: 40px" disabled>@hours:@minutes</button>
                                }
                                }
                                else if (showtimeDay > currentDay)
                                {                                    
                        <div class="showtime">@Html.ActionLink(hours + ":" + minutes, "BookingAFilmTicket", "Schedule", new { @showtimeId = item.ShowTime.ShowTimeId, @filmId = item.FilmId, @theaterId = item.TheaterId, @roomId = item.RoomId, @scheduleId = item.ScheduleId }, new {style="color:white" })</div>
                                }
                            }
                              <div style="border-top:solid 1px #ddd;margin-top:10px;border-bottom:1px solid #fff"></div>
                        }
                    }
                    }

                </div>
            </div>
                }
            }
            }
                
    </div>
}
else{
    <div class="panel" style="background-color: white; margin-top: 20px; margin-left: 15px; width: 97.5%;height:455px;text-align:center;">
      <h2>  Hiện tại không có phim khuyến mãi</h2>
    </div>
}


